<?php



namespace Bingo\Commands;

use Bingo\BingoStart;
use Bingo\Facade\Module;
use Illuminate\Support\Collection;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ModuleInstallCommand extends BingoCommand
{
    protected $signature = 'bingo:module:install {module} {--f}';

    protected $description = 'install bingo module';

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return void
     */
    protected function initialize(InputInterface $input, OutputInterface $output): void
    {
        if (! $this->option('f')) {
            if ($input->hasArgument('module')
                && Module::getEnabled()->pluck('name')->merge(Collection::make(config('bingo.module.default')))->contains(lcfirst($input->getArgument('module')))
            ) {
                $this->error(sprintf('Module [%s] Has installed', $input->getArgument('module')));
                exit;
            }
        }
    }

    public function handle(): void
    {
        $installer = BingoStart::getModuleInstaller($this->argument('module'));

        $installer->install();
    }
}
